# -*- coding: utf-8 -*-
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'TuringClass.settings')
import django
from app_TuringClass.models import *
from app_accounts.models import *
from app_OnlineExam.models import *
from django.contrib.auth.models import User
import datetime
## author：houchaoqun
## function：初始化用户数据库
## date：2016/11/10

def Population():
	AddCourse("001", "高等数学")
	AddCourse("002", "高等代数")
	AddCourse("003", "C/C++")
	AddCourse("004", "英语")
	AddCourse("005", "思政课")
	AddCourse("006", "问卷调查")

	Add_defaultSingleProblem(51,'001',"选择题1","A选项","B选项","C选项","D选项",'A',"选A",4)
	Add_defaultSingleProblem(52,'001',"选择题2","a选项","b选项","c选项","d选项",'B',"选B",4)
	Add_defaultSingleProblem(53,'001',"选择题3","A选项","B选项","C选项","D选项",'C',"选C",4)
	Add_DefaultJudgement(1,'001',"判断题1",'A',"选正确",4)
	Add_DefaultJudgement(2,'001',"判断题2",'B',"选错误",4)

	Add_DefaultExam('2017_4_2_21_46',"期中考试",'s1_s2_j1_s3_j2','001','60','5','20',"TuringClass","TuringClass")

	Add_defaultSingleProblem(1,'004',"All but Jane and I ______ going to cinema tonight.","are","is","am","will",'C',"None",2)
	Add_defaultSingleProblem(2,'004',"Jane is not ______ to attend Sally¡¯s birthday party, for they had a quarrel last Friday.","likely","possibly","probably","willingly",'A',"None",2)
	Add_defaultSingleProblem(3,'004',"______ to Jane's parents, Tonny looked a bit nervous and upset.","This being his first visit","This being his first time to visit","Having never visited before","Having never visited before",'A',"None",2)
	Add_defaultSingleProblem(4,'004',"We firmly ______ in the future victory of the revolution.","specialize","participate","believe","delight",'C',"None",2)
	Add_defaultSingleProblem(5,'004',"It is essential to be on friendly___with neighbors.","connection","association","terms","relations",'D',"None",2)
	Add_defaultSingleProblem(6,'004',"The professor paused as if___his students to ask questions on the point he had just made.","expecting","to expect","having expected","to have expected",'B',"None",2)
	Add_defaultSingleProblem(7,'004',"It was in this house ______ the important meeting in history was held.","where","that","which","in which",'B',"None",2)
	Add_defaultSingleProblem(8,'004',"He was___selling military secrets to foreign intelligence agencies.","charged of","accused of","approved of","deprived of",'B',"None",2)
	Add_defaultSingleProblem(9,'004',"Mother asks Sally ______ up as early as usual though it is Sunday.","gets","got","had got","get",'D',"None",2)
	Add_defaultSingleProblem(10,'004',"______ clear was his statement that it couldn¡¯t be misunderstood.","Too","Enough","Much","So",'D',"None",2)
	Add_defaultSingleProblem(11,'004',"After___to prison, they regret not having taken advice from their parents and friends.","have sent","have been sent","having sent","being sent",'D',"None",2)
	Add_defaultSingleProblem(12,'004',"I___like that had you told me the truth earlier.","would not have done","would not do","will not do","would do",'A',"None",2)
	Add_defaultSingleProblem(13,'004',"It is___to make a long train journey to have a look at so beautiful a scene.","worth","worthwhile","worthy","deserve",'B',"None",2)
	Add_defaultSingleProblem(14,'004',"One of Bettie¡¯s brothers was killed in action, another ______.","takes prisoner","took prisoner","taken prisoner","taking prisoner",'C',"None",2)
	Add_defaultSingleProblem(15,'004',"______ most of the teachers in her school, Miss Lee loves her job and the pupils as well.","As","Like","For","Being",'B',"None",2)
	Add_defaultSingleProblem(16,'004',"Has Jenny's plane landed?No, but it___here in a few minutes.","may have been","ought to be","should have been","has to be",'B',"None",2)
	Add_defaultSingleProblem(17,'004',"She was honest enough to admit___errors in judgment on more than one occasion.","to make","making","to commit","being commited",'B',"None",2)
	Add_defaultSingleProblem(18,'004',"News got round ______ he had resigned his position as executive secretary of the committee.","when","that","which","after",'B',"None",2)
	Add_defaultSingleProblem(19,'004',"You may ______ this magazine home to read, but you¡¯ll have to ______ it back to me tomorrow morning.","fetch, carry","carry, fetch","take, bring","bring, take",'C',"None",2)
	Add_defaultSingleProblem(20,'004',"Will you ______ that each child gets a copy of the new picture book?","see","observe","watch","stare",'B',"None",2)
	Add_defaultSingleProblem(21,'004',"He was only one man in the city ______ of lending you ¡ê10 000.","capable","able","willing","generous",'A',"None",2)
	Add_defaultSingleProblem(22,'004',"¡ªHow about taking a walk? Oh, I think it's ______ cold for a walk.","very much","too much","much too","so much",'C',"None",2)
	Add_defaultSingleProblem(23,'004',"Jones seems interested in___you have told her.","all that","all what","that","this",'B',"None",2)
	Add_defaultSingleProblem(24,'004',"We all don't think ______ she left for Boston yesterday.","that it true","it true that","it that true","that true it",'B',"None",2)
	Add_defaultSingleProblem(25,'004',"You___us about his departure a week ago.","ought to have told","have told","had told","might as well tell",'A',"None",2)
	Add_defaultSingleProblem(26,'004',"I ______ writing the paper had I not run out of ink.","finished","have finished","had finished","would have finished",'D',"None",2)
	Add_defaultSingleProblem(27,'004',"We must make some investigations___we can draw any conclusion.","since","before","until","when",'B',"None",2)
	Add_defaultSingleProblem(28,'004',"There are___when you cannot refuse your friend's offer.","occasions","situations","chances","conditions",'B',"None",2)
	Add_defaultSingleProblem(29,'004',"______, the little girl did not open the door.","Not recognizing who the man was","Not being recognized who was the man","Not recognized who the man was","Not recognizing who was the man",'A',"None",2)
	Add_defaultSingleProblem(30,'004',"He used to take a walk after supper each day,___?","did he","was he","usedn't","wasn't he",'C',"None",2)
	Add_defaultSingleProblem(31,'004',"I appreciate___that letter for me.","Tonny to write","Tonny write","Tonny writing","that Tonny write",'C',"None",2)
	Add_defaultSingleProblem(32,'004',"Like ______ other language skills, reading requires practice.","most of the","the most","much of the","the more",'A',"None",2)
	Add_defaultSingleProblem(33,'004',"The captain received an order that the rescue work___owing to an approaching storm.","stop","stops","stopped","be stopped",'D',"None",2)
	Add_defaultSingleProblem(34,'004',"We must not rule  ___the possibility of miscalculation.","away","up","out","off",'C',"None",2)
	Add_defaultSingleProblem(35,'004',"______ he realized it was too late to return home.","No sooner it grew dark when","Hardly it grew dark than","It was not until dark that","Before it grew dark",'C',"None",2)
	Add_defaultSingleProblem(36,'004',"She looked as if she___miseries of all sorts while telling us her life in the country.","experienced","had experienced","experience","should experience",'B',"None",2)
	Add_defaultSingleProblem(37,'004',"We are so busy that we had to ______ our vacation till next month.","put away","put down","put off","put out",'C',"None",2)
	Add_defaultSingleProblem(38,'004',"To make room for more machinery, the factory___now.","is enlarged","is to enlarge","is to be enlarging","is being enlarged",'D',"None",2)
	Add_defaultSingleProblem(39,'004',"One of my teeth is so ______ that it is going to be missing soon.","lose","loose","loss","lost",'B',"None",2)
	Add_defaultSingleProblem(40,'004',"It was because the applicant was too conceited ___he failed in the interview.","so","that","so that","therefore",'B',"None",2)
	Add_defaultSingleProblem(41,'004',"Many a boy___tried, but ___have succeeded.","have, many","has, few","has, a few","have, a number",'B',"None",2)
	Add_defaultSingleProblem(42,'004',"A student of average intelligence can be a top student. Cathy is a___in point.","example","instance","case","illustration",'C',"None",2)
	Add_defaultSingleProblem(43,'004',"She has changed so much that I could hardly ______ her.","know","realize","rememer","recognize",'D',"None",2)
	Add_defaultSingleProblem(44,'004',"On second day, he had his car thoroughly ______ before embarking on the journey.","to be examined","being examined","examined","was examined",'C',"None",2)
	Add_defaultSingleProblem(45,'004',"She looked so honest that we all regarded her story ______.","like true","as true","like real","as real",'B',"None",2)
	Add_defaultSingleProblem(46,'004',"Don't leave the baby alone in the yard___ .","on no account","on any account","on the account","on some account",'B',"None",2)
	Add_defaultSingleProblem(47,'004',"The experiment___the discovery of a cure for cancer.","set up","called off","resulted in","longed for",'D',"None",2)
	Add_defaultSingleProblem(48,'004',"Jane put forward the proposal that the program ______ until Mr. Power came back from abroad.","postponed","had been postponed","be postponed","would be postponed",'C',"None",2)
	Add_defaultSingleProblem(49,'004',"This broadcast comes to us ______ from the stadium.","lively","living","alive","live",'D',"None",2)
	Add_defaultSingleProblem(50,'004',"___in the earthquake, the theatre had to be renovated in 1956.","Having damaged","It was damaged","Damaged","having been damaged",'D',"None",2)

	Add_DefaultExam('2017_4_28_10_1',"英语练习",'s1_s2_s3_s4_s5_s6_s7_s8_s9_s10_s11_s12_s13_s14_s15_s16_s17_s18_s19_s20_s21_s22_s23_s24_s25_s26_s27_s28_s29_s30_s31_s32_s33_s34_s35_s36_s37_s38_s39_s40_s41_s42_s43_s44_s45_s46_s47_s48_s49_s50','004','60','50','200',"TuringClass","TuringClass")


def AddCourse(CourseID, CourseName):
	print "[CourseID] = ",CourseID
	if Course.objects.filter(CourseID = CourseID).exists():
		print "[Course has been existed...]",CourseName
	else:
		NewCourse = Course.objects.get_or_create(CourseID = CourseID, CourseName = CourseName)[0]
		NewCourse.save()
		print "-- function [AddCourse] successful... "

def Add_defaultSingleProblem(QuestionID,CourseID,QuestionTitle,OptionA,OptionB,OptionC,OptionD,SingleAnswer,Analysis,weight):
	if SingleSelectProblem.objects.filter(QuestionID = QuestionID).exists():
		print "[SingleQuestionID has been existed...]"
	else:	
		SingleSelectProblem(QuestionID = QuestionID,CourseID = CourseID,QuestionTitle = QuestionTitle,OptionA = OptionA,OptionB = OptionB,OptionC = OptionC,OptionD =OptionD,SingleAnswer = SingleAnswer,Analysis = Analysis,Weight = weight).save()
		print "[Add_defaultSingleProblem  successful...]"
def Add_DefaultJudgement(QuestionID,CourseID,QuestionTitle,JudgementAnswer,Analysis,Weight):
	if JudgementProblem.objects.filter(QuestionID = QuestionID).exists():
		print "[JudgementQuestionID has been existed...]"
	else:
		JudgementProblem(QuestionID = QuestionID,CourseID = CourseID,QuestionTitle = QuestionTitle,JudgementAnswer =JudgementAnswer,Analysis = Analysis,Weight = Weight).save()
		print "[Add_defaultJudgement successful...]"
def Add_DefaultExam(ExamID,ExamName,ExamQuestions,CourseID,ExamTime,Problemnum,TotalScore,TeacherID,Note):
	if ExamPaperInfo.objects.filter(ExamID = ExamID).exists():
		print "[ExamID has been existed...]"
	else:
		ExamPaperInfo(ExamID = ExamID,ExamName = ExamName,ExamQuestions =ExamQuestions,CourseID =CourseID,ExamTime = ExamTime,ProblemNum = Problemnum,TotalScore = TotalScore,TeacherID = TeacherID,Note = Note).save()
		print "[Add_DefaultExam successful...]"

### main program
if __name__ == '__main__':
	print 'DB_OnlineExam_init.py - running...'
	Population()
